<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="号码" prop="tel">
        <el-input
          v-model="queryParams.tel"
          placeholder="请输入号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hmk:tel:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hmk:tel:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hmk:tel:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hmk:tel:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="telList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键" align="center" prop="id"/>
      <el-table-column label="号码" align="center" prop="tel"/>
      <el-table-column label="状态1上架中(出售中)2已预订3已下架" align="center" prop="state"/>
      <el-table-column label="所含话费" align="center" prop="bill"/>
      <el-table-column label="统一售价" align="center" prop="price"/>
      <el-table-column label="结算底价" align="center" prop="floorprice"/>
      <el-table-column label="上传底价" align="center" prop="uploadfloorprice"/>
      <el-table-column label="说明" align="center" prop="content"/>
      <el-table-column label="运营商" align="center" prop="classId"/>
      <el-table-column label="规律段" align="center" prop="segmentId"/>
      <el-table-column label="号码段" align="center" prop="abcId"/>
      <el-table-column label="号码仓" align="center" prop="supplierId"/>
      <el-table-column label="是否置顶1否2是" align="center" prop="istop"/>
      <el-table-column label="添加时间" align="center" prop="time"/>
      <el-table-column label="是否参与秒杀1不是2是" align="center" prop="type"/>
      <el-table-column label="秒杀时间" align="center" prop="killingtime"/>
      <el-table-column label="秒杀定金" align="center" prop="deposit"/>
      <el-table-column label="秒杀价格" align="center" prop="killprice"/>
      <el-table-column label="秒杀状态1未秒杀2已秒杀" align="center" prop="killstate"/>
      <el-table-column label="秒杀时间" align="center" prop="killtime"/>
      <el-table-column label="有无低消1有2无" align="center" prop="isDissipation"/>
      <el-table-column label="有无卡费1有2无" align="center" prop="isCardprice"/>
      <el-table-column label="1F推荐靓号区的所有号码笔画1-81" align="center" prop="xionghua"/>
      <el-table-column label="1F推荐靓号区的所有号码性格1-9" align="center" prop="xingess"/>
      <el-table-column label="数字几多" align="center" prop="numbercount"/>
      <el-table-column label="添加人" align="center" prop="manageId"/>
      <el-table-column label="t2" align="center" prop="t2"/>
      <el-table-column label="t3" align="center" prop="t3"/>
      <el-table-column label="t4" align="center" prop="t4"/>
      <el-table-column label="t5" align="center" prop="t5"/>
      <el-table-column label="t6" align="center" prop="t6"/>
      <el-table-column label="t7" align="center" prop="t7"/>
      <el-table-column label="t8" align="center" prop="t8"/>
      <el-table-column label="t9" align="center" prop="t9"/>
      <el-table-column label="t10" align="center" prop="t10"/>
      <el-table-column label="t11" align="center" prop="t11"/>
      <el-table-column label="添加批次" align="center" prop="batch"/>
      <el-table-column label="阅读量" align="center" prop="volume"/>
      <el-table-column label="真实阅读量" align="center" prop="isVolume"/>
      <el-table-column label="上传用户类型1总后台添加2商户添加" align="center" prop="addtype"/>
      <el-table-column label="商户id" align="center" prop="businessId"/>
      <el-table-column label="归属地省份" align="center" prop="shengname"/>
      <el-table-column label="归属地市" align="center" prop="cityname"/>
      <el-table-column label="每月保底消费(元)" align="center" prop="baodiprice"/>
      <el-table-column label="保底协议时长(月)" align="center" prop="xieyimonth"/>
      <el-table-column label="置顶开始时间" align="center" prop="istopstartTime"/>
      <el-table-column label="置顶结束时间" align="center" prop="istopendTime"/>
      <el-table-column label="号码来源1号码库上传2接口插入(智慧云厅接口)3接口插入(号码小铺接口ZOP)" align="center"
                       prop="sourceType"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hmk:tel:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hmk:tel:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改号码对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="号码" prop="tel">
          <el-input v-model="form.tel" placeholder="请输入号码"/>
        </el-form-item>
        <el-form-item label="状态1上架中(出售中)2已预订3已下架" prop="state">
          <el-input v-model="form.state" placeholder="请输入状态1上架中(出售中)2已预订3已下架"/>
        </el-form-item>
        <el-form-item label="所含话费" prop="bill">
          <el-input v-model="form.bill" placeholder="请输入所含话费"/>
        </el-form-item>
        <el-form-item label="统一售价" prop="price">
          <el-input v-model="form.price" placeholder="请输入统一售价"/>
        </el-form-item>
        <el-form-item label="结算底价" prop="floorprice">
          <el-input v-model="form.floorprice" placeholder="请输入结算底价"/>
        </el-form-item>
        <el-form-item label="上传底价" prop="uploadfloorprice">
          <el-input v-model="form.uploadfloorprice" placeholder="请输入上传底价"/>
        </el-form-item>
        <el-form-item label="说明">
          <editor v-model="form.content" :min-height="192"/>
        </el-form-item>
        <el-form-item label="运营商" prop="classId">
          <el-input v-model="form.classId" placeholder="请输入运营商"/>
        </el-form-item>
        <el-form-item label="规律段" prop="segmentId">
          <el-input v-model="form.segmentId" placeholder="请输入规律段"/>
        </el-form-item>
        <el-form-item label="号码段" prop="abcId">
          <el-input v-model="form.abcId" placeholder="请输入号码段"/>
        </el-form-item>
        <el-form-item label="号码仓" prop="supplierId">
          <el-input v-model="form.supplierId" placeholder="请输入号码仓"/>
        </el-form-item>
        <el-form-item label="是否置顶1否2是" prop="istop">
          <el-input v-model="form.istop" placeholder="请输入是否置顶1否2是"/>
        </el-form-item>
        <el-form-item label="添加时间" prop="time">
          <el-input v-model="form.time" placeholder="请输入添加时间"/>
        </el-form-item>
        <el-form-item label="秒杀时间" prop="killingtime">
          <el-input v-model="form.killingtime" placeholder="请输入秒杀时间"/>
        </el-form-item>
        <el-form-item label="秒杀定金" prop="deposit">
          <el-input v-model="form.deposit" placeholder="请输入秒杀定金"/>
        </el-form-item>
        <el-form-item label="秒杀价格" prop="killprice">
          <el-input v-model="form.killprice" placeholder="请输入秒杀价格"/>
        </el-form-item>
        <el-form-item label="秒杀状态1未秒杀2已秒杀" prop="killstate">
          <el-input v-model="form.killstate" placeholder="请输入秒杀状态1未秒杀2已秒杀"/>
        </el-form-item>
        <el-form-item label="秒杀时间" prop="killtime">
          <el-input v-model="form.killtime" placeholder="请输入秒杀时间"/>
        </el-form-item>
        <el-form-item label="有无低消1有2无" prop="isDissipation">
          <el-input v-model="form.isDissipation" placeholder="请输入有无低消1有2无"/>
        </el-form-item>
        <el-form-item label="有无卡费1有2无" prop="isCardprice">
          <el-input v-model="form.isCardprice" placeholder="请输入有无卡费1有2无"/>
        </el-form-item>
        <el-form-item label="1F推荐靓号区的所有号码笔画1-81" prop="xionghua">
          <el-input v-model="form.xionghua" placeholder="请输入1F推荐靓号区的所有号码笔画1-81"/>
        </el-form-item>
        <el-form-item label="1F推荐靓号区的所有号码性格1-9" prop="xingess">
          <el-input v-model="form.xingess" placeholder="请输入1F推荐靓号区的所有号码性格1-9"/>
        </el-form-item>
        <el-form-item label="数字几多" prop="numbercount">
          <el-input v-model="form.numbercount" placeholder="请输入数字几多"/>
        </el-form-item>
        <el-form-item label="添加人" prop="manageId">
          <el-input v-model="form.manageId" placeholder="请输入添加人"/>
        </el-form-item>
        <el-form-item label="t2" prop="t2">
          <el-input v-model="form.t2" placeholder="请输入t2"/>
        </el-form-item>
        <el-form-item label="t3" prop="t3">
          <el-input v-model="form.t3" placeholder="请输入t3"/>
        </el-form-item>
        <el-form-item label="t4" prop="t4">
          <el-input v-model="form.t4" placeholder="请输入t4"/>
        </el-form-item>
        <el-form-item label="t5" prop="t5">
          <el-input v-model="form.t5" placeholder="请输入t5"/>
        </el-form-item>
        <el-form-item label="t6" prop="t6">
          <el-input v-model="form.t6" placeholder="请输入t6"/>
        </el-form-item>
        <el-form-item label="t7" prop="t7">
          <el-input v-model="form.t7" placeholder="请输入t7"/>
        </el-form-item>
        <el-form-item label="t8" prop="t8">
          <el-input v-model="form.t8" placeholder="请输入t8"/>
        </el-form-item>
        <el-form-item label="t9" prop="t9">
          <el-input v-model="form.t9" placeholder="请输入t9"/>
        </el-form-item>
        <el-form-item label="t10" prop="t10">
          <el-input v-model="form.t10" placeholder="请输入t10"/>
        </el-form-item>
        <el-form-item label="t11" prop="t11">
          <el-input v-model="form.t11" placeholder="请输入t11"/>
        </el-form-item>
        <el-form-item label="添加批次" prop="batch">
          <el-input v-model="form.batch" placeholder="请输入添加批次"/>
        </el-form-item>
        <el-form-item label="阅读量" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入阅读量"/>
        </el-form-item>
        <el-form-item label="真实阅读量" prop="isVolume">
          <el-input v-model="form.isVolume" placeholder="请输入真实阅读量"/>
        </el-form-item>
        <el-form-item label="商户id" prop="businessId">
          <el-input v-model="form.businessId" placeholder="请输入商户id"/>
        </el-form-item>
        <el-form-item label="归属地省份" prop="shengname">
          <el-input v-model="form.shengname" placeholder="请输入归属地省份"/>
        </el-form-item>
        <el-form-item label="归属地市" prop="cityname">
          <el-input v-model="form.cityname" placeholder="请输入归属地市"/>
        </el-form-item>
        <el-form-item label="每月保底消费(元)" prop="baodiprice">
          <el-input v-model="form.baodiprice" placeholder="请输入每月保底消费(元)"/>
        </el-form-item>
        <el-form-item label="保底协议时长(月)" prop="xieyimonth">
          <el-input v-model="form.xieyimonth" placeholder="请输入保底协议时长(月)"/>
        </el-form-item>
        <el-form-item label="置顶开始时间" prop="istopstartTime">
          <el-input v-model="form.istopstartTime" placeholder="请输入置顶开始时间"/>
        </el-form-item>
        <el-form-item label="置顶结束时间" prop="istopendTime">
          <el-input v-model="form.istopendTime" placeholder="请输入置顶结束时间"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addTel, delTel, getTel, listTel, updateTel} from "@/api/hmk/tel";

export default {
  name: "Tel",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 号码表格数据
      telList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tel: null,
        state: null,
        bill: null,
        price: null,
        floorprice: null,
        uploadfloorprice: null,
        content: null,
        classId: null,
        segmentId: null,
        abcId: null,
        supplierId: null,
        istop: null,
        time: null,
        type: null,
        killingtime: null,
        deposit: null,
        killprice: null,
        killstate: null,
        killtime: null,
        isDissipation: null,
        isCardprice: null,
        xionghua: null,
        xingess: null,
        numbercount: null,
        manageId: null,
        t2: null,
        t3: null,
        t4: null,
        t5: null,
        t6: null,
        t7: null,
        t8: null,
        t9: null,
        t10: null,
        t11: null,
        batch: null,
        volume: null,
        isVolume: null,
        addtype: null,
        businessId: null,
        shengname: null,
        cityname: null,
        baodiprice: null,
        xieyimonth: null,
        istopstartTime: null,
        istopendTime: null,
        sourceType: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询号码列表 */
    getList() {
      this.loading = true;
      listTel(this.queryParams).then(response => {
        this.telList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tel: null,
        state: null,
        bill: null,
        price: null,
        floorprice: null,
        uploadfloorprice: null,
        content: null,
        classId: null,
        segmentId: null,
        abcId: null,
        supplierId: null,
        istop: null,
        time: null,
        type: null,
        killingtime: null,
        deposit: null,
        killprice: null,
        killstate: null,
        killtime: null,
        isDissipation: null,
        isCardprice: null,
        xionghua: null,
        xingess: null,
        numbercount: null,
        manageId: null,
        t2: null,
        t3: null,
        t4: null,
        t5: null,
        t6: null,
        t7: null,
        t8: null,
        t9: null,
        t10: null,
        t11: null,
        batch: null,
        volume: null,
        isVolume: null,
        addtype: null,
        businessId: null,
        shengname: null,
        cityname: null,
        baodiprice: null,
        xieyimonth: null,
        istopstartTime: null,
        istopendTime: null,
        sourceType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加号码";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTel(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改号码";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTel(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTel(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除号码编号为"' + ids + '"的数据项？').then(function () {
        return delTel(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hmk/tel/export', {
        ...this.queryParams
      }, `tel_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
